<template>
  <van-row class="panel-carrier-list">
    <van-nav-bar
      left-text="返回"
      title="选择考核载体"
      @click-left="$emit('onCancel')"/>
    <van-cell-group>
      <card-carrier-item
        v-for="(carrier) in carrierList"
        :key="carrier.id"
        :carrier="carrier"
        @onClick="doClick"/>
    </van-cell-group>
    <loading-overlay :show="isLoading"/>
    <van-popup
      v-model="showPageContentItemList"
      position="right"
      get-container="body"
      style="width: 100%; height: 100%; background-color: #F9F9F9">
      <page-content-item-list v-if="showPageContentItemList" :carrier="this.selectedCarrier" :type="this.type" v-on:onConfirm="endSelectCheckItem" v-on:onCancel="showPageContentItemList = false"/>
    </van-popup>
  </van-row>
</template>

<script>
import PageContentItemList from '@/views/common/page/PageContentItemList'
import CardCarrierItem from '@/views/common/card/CardCarrierItem'
import { getCarrierList } from '@/api/assess'
export default {
  name: 'PageCarrierItemList',
  components: { PageContentItemList, CardCarrierItem },
  props: ['carrier', 'type'],
  data () {
    return {
      isLoading: false,
      showPageContentItemList: false,
      carrierList: [],
      selectedCarrier: this.$vo.createCarrier()
    }
  },
  mounted () {
    this.doGetCarrierList()
  },
  methods: {
    doClick (carrier) {
      this.selectedCarrier.id = carrier.id
      this.selectedCarrier.item = carrier.item
      this.showPageContentItemList = true
    },
    endSelectCheckItem (content) {
      this.showPageContentItemList = false
      let carrier = {}
      carrier.id = this.selectedCarrier.id
      carrier.item = this.selectedCarrier.item
      carrier.content_item = content
      this.$emit('onConfirm', carrier)
    },
    doGetCarrierList () {
      this.isLoading = true
      getCarrierList(this.type).then(res => {
        this.isLoading = false
        let { data } = res
        if (data[this.$response.CODE] === this.$response.SUCCESS) {
          this.carrierList = data[this.$response.DATA].check_list
          this.carrierList.sort((obj1, obj2) => {
            var val1 = Number(obj1.id)
            var val2 = Number(obj2.id)
            if (val1 < val2) {
              return -1
            } else {
              return 1
            }
          })
        } else {
          this.$toast.fail('获取数据失败：' + data[this.$response.MESSAGE])
        }
      }, errFunc => {
        this.isLoading = false
        this.$notify('服务调用失败：' + errFunc.toString())
        console.log(errFunc.toString())
      })
    }
  }
}
</script>

<style scoped lang="less">

</style>
